// Datapump to obtain progress, interface to report it.
// Copyright 2006 (C) Ralph Thomas

#ifndef MISSION_DATAPUMPS_PROGRESS_H
#define MISSION_DATAPUMPS_PROGRESS_H

#include <adobe/dictionary.hpp>
#include <adobe/any_regular.hpp>
#include <adobe/adam.hpp>

namespace datapumps {
	//
	/// The progress_report_t structure allows progress to be
	/// reported through the datapumps from some code that is
	/// performing an operation that will take some time. It
	/// does thread locking itself.
	//
	struct progress_report_t {
		//
		/// Create a new progress_report_t with the given name.
		/// This name will probably show up in the UI, so should
		/// be something along the lines of "Import Progress",
		/// for example.
		///
		/// \param	name	the name of the progress to report.
		//
		progress_report_t( const std::string& name );
		//
		/// When the progress_report_t instance goes out of scope
		/// it will no longer be listed in the UI.
		//
		~progress_report_t();
		//
		/// This method should be called whenever the count of
		/// things to do changes.
		///
		/// \param	count		the number of things to do.
		//
		void set_count(unsigned int count);
		//
		/// This method should be called whenever the progress
		/// changes.
		///
		/// \param	count		the number of things to do.
		/// \param	progress	the number of things done.
		/// \param	url			the URL being processed, if applicable.
		//
		void state_progress(unsigned int progress, const std::string& url);
	  private:
		unsigned int id_m;
	};
	//
	/// Create a datapump that returns a list of all of the things
	/// in progress.
	//
	adobe::any_regular_t make_progress_items_datapump();
	//
	/// Create a datapump that returns the URL being processed by
	/// the item in the first entry in the array (returned by
	/// make_progress_items_datapump()).
	///
	/// \param	array	an array containing an item as returned
	///					in the array from the progress_items
	///					datapump.
	/// \param	sheet	the sheet to resolve \@names into.
	//
	adobe::any_regular_t make_progress_url_datapump( const adobe::array_t& array, adobe::sheet_t& sheet );
	//
	/// Create a datapump that returns the percentage of the
	/// progress of the given item.
	///
	/// \param	array	an array containing an item as returned
	///					in the array from the progress_items
	///					datapump.
	/// \param	sheet	the sheet to resolve \@names into.
	//
	adobe::any_regular_t make_progress_percentage_datapump( const adobe::array_t& array, adobe::sheet_t& sheet );
	//
	/// Create a datapump that returns the name of the given
	/// progress item.
	///
	/// \param	array	an array containing an item as returned
	///					in the array from the progress_items
	///					datapump.
	/// \param	sheet	the sheet to resolve \@names into.
	//
	adobe::any_regular_t make_progress_name_datapump( const adobe::array_t& array, adobe::sheet_t& sheet );
};

#endif

